package P7;

public class P7_reverse {
    public static void main(String[] args) throws Exception {

        System.out.println(new P7_reverse().reverse(123));
    }

    public int reverse(int x) {

        if (x == 0) {
            return 0;
        }

        String s = String.valueOf(Math.abs(x));
        StringBuilder sb = new StringBuilder(s);
        sb = sb.reverse();
        try {
            int result = Integer.valueOf(sb.toString());

            if (x < 0) {
                return -result;
            } else {
                return result;
            }
        } catch (Exception e) {
            return 0;
        }

    }
}
